﻿<!DOCTYPE html>
<head>
    <meta charset="UTF-8">

    <script type="text/javascript">

        const url = "wss://localhost:8081/"
		var pc;
	
		async function start() {
	
			console.log("start peer");
	
			const constraints = {'audio': true }	
			let pc = new RTCPeerConnection();
			
			pc.onsignalingstatechange = ({ev}) => console.log("onsignalingstatechange: " + pc.signalingState + ", "+ ev);
			
			pc.onicecandidate = ({candidate}) => console.log(candidate);

			pc.onnegotiationneeded = async () => {
				await pc.setLocalDescription();
				console.log(pc.localDescription.sdp);
			};
			
			const stream = await navigator.mediaDevices.getUserMedia(constraints);
			stream.getTracks().forEach((track) => pc.addTrack(track, stream));
		};

		function closePeer() {
			console.log("close peer");
			if(pc != null) {
				pc.close();
			}
		};

    </script>
</head>
<body>

    <video controls autoplay="autoplay" id="videoCtl" width="640" height="480"></video>
	
    <div>
        <button type="button" class="btn btn-success" onclick="start();">Start</button>
		<button type="button" class="btn btn-success" onclick="closePeer();">Close</button>
    </div>

</body>
